package com.example.dingdong.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.dingdong.daomain.MenuEntity;
import com.example.dingdong.daomain.OrderRecordEntity;
import com.example.dingdong.repository.OrderRecordRepository;
/**
 * 
 * @ClassName: OrderService
 * @Description: 
 * @Author :chengwenixng
 * @DateTime 2022-03-27 13:49:58
 */
@Service
public class OrderService {
	
	private static final Logger log = LoggerFactory.getLogger(OrderService.class);

	@Autowired
	private OrderRecordRepository orderRecordRepository;
	/**
	 * 
	 * @Title: allOrderInformationData
	 * @Description: 
	 * @Author coding
	 * @DateTime 2022-03-25 22:34:54
	 * @return
	 */
	public List<OrderRecordEntity> allOrderInformationData() {
		//获取去用户信息
		Subject currentUser = SecurityUtils.getSubject();
		if (currentUser.isAuthenticated()) {
			log.info("用户已经登录!");
		}
		List<OrderRecordEntity> orderList  = new ArrayList<>();
		try {
			/**
			 * 查找数据
			 */
			orderList  = orderRecordRepository.findByDelFlag(true);
		} catch (Exception e) {
			return new ArrayList<>();
		}
		return orderList;
	}
	/**
	 * 
	 * @Title: getOrderRecords
	 * @Description: 
	 * @Author coding
	 * @DateTime 2022-03-25 23:33:16
	 * @param id
	 * @param deLFlag
	 * @return
	 */
	public  OrderRecordEntity getOrderRecords(Long id,Boolean deLFlag) {
		return orderRecordRepository.findByIdAndDelFlag(id, true);
	}
	/**
	 * 
	 * @Title: savaOrderEntities
	 * @Description: 
	 * @Author coding
	 * @DateTime 2022-03-25 23:31:46
	 * @param orderRecordEntity
	 * @return
	 */
	public OrderRecordEntity savaOrderEntities(OrderRecordEntity orderRecordEntity) {
		return orderRecordRepository.save(orderRecordEntity);
	}
	/**
	 * 
	 * @Title: getOrderRecordInformation
	 * @Description: 
	 * @Author coding
	 * @DateTime 2022-03-27 10:38:01
	 * @param id
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public List<Object[]> getOrderRecordInformation(Long id, Date startTime, Date endTime) {
		List<Object[]> orderRecordInformation =  orderRecordRepository.findOrderRecordInformation(id,startTime, endTime);	
		return orderRecordInformation;
	}
	
	public List<OrderRecordEntity> getTodayOrdering(Long id,Date startTime, Date endTime) {
		List<OrderRecordEntity> OrderList = new ArrayList<>();
		try {
			/**
			 * 查找数据
			 */
			OrderList = orderRecordRepository.getTodayOrder(id,startTime, endTime);
		} catch (Exception e) {
			log.error("getOrderRecordInformation:");
			return new ArrayList<>();
		}
		return OrderList;
	}

}
